package com.wx.wxapp.controller;


import com.wx.wxapp.entity.Pet;
import com.wx.wxapp.service.PetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class PetController {
    @Autowired
    private PetService petService;
    /*
     *   功能：获取用户添加的宠物信息
     *   参数：
     *       openid:用户的openid
     * */
    @RequestMapping(value = "/getpet",method = RequestMethod.GET)
    public Pet GetPet( @RequestParam("openid") String openid){
        return petService.getPet(openid);
    }

    /*
     *   功能：修改宠物信息
     *   参数：
     *       name:宠物名字
     *       age:宠物年龄
     *       sex:宠物性别
     *       variety:宠物种类
     *       introduction:宠物介绍
     *       id:宠物的id
     *       openid:用户openid
     * */
    @RequestMapping(value = "/changePetInfo",method = RequestMethod.POST)
    public void changePetInfo(@RequestParam("name")String name,@RequestParam("age")Integer age,
                          @RequestParam("sex")String sex,@RequestParam("variety")String variety,
                          @RequestParam("introduction")String introduction, @RequestParam("openid")String openid){
         //用户没有输入年龄时，将年龄用0代替
         if (age==null){
             age = 0;
         }
         petService.changePetInfo(name,age,sex,variety,introduction,openid);
    }

    @RequestMapping(value = "/getPetAndImage",method = RequestMethod.GET)
    public Map GetPetAndImage(@RequestParam("id")int id){
        return petService.getPetAndImage(id);
    }

    @RequestMapping(value = "/getPetId",method = RequestMethod.GET)
    public int GetPetId(@RequestParam("status")String status){
        return petService.GetPetId(status);
    }
}
